﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:controls="clr-namespace:MsgBox.View.Modern"

                    xmlns:syscmd="clr-namespace:Microsoft.Windows.Shell;assembly=Microsoft.Windows.Shell"
                    xmlns:shell="http://schemas.microsoft.com/winfx/2006/xaml/presentation/shell"
                    
                    xmlns:local="clr-namespace:MsgBox.View.Modern"
                    xmlns:xc="clr-namespace:MsgBox.View.Modern.Behavior"
                    >

  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="/MsgBox;component/View/Modern/Themes/Button.xaml" />
    <ResourceDictionary Source="/MsgBox;component/View/Modern/Themes/Converters.xaml" />
  </ResourceDictionary.MergedDictionaries>

  <!-- additional ModernWindow styles -->
  <Style x:Key="MsgSystemButton" TargetType="ButtonBase" BasedOn="{StaticResource SystemButtonBase}">
    <Setter Property="Foreground" Value="{DynamicResource LinkButtonText}"/>
    <Style.Triggers>
      <Trigger Property="IsMouseOver" Value="True">
        <Setter Property="Foreground" Value="{DynamicResource LinkButtonTextHover}"/>
        <Setter Property="Background" Value="{DynamicResource SystemButtonMouseOverBackgroundColor}" />
      </Trigger>
      <Trigger Property="IsPressed" Value="True">
        <Setter Property="Foreground" Value="{DynamicResource LinkButtonTextPressed}" />
      </Trigger>
      <Trigger Property="IsEnabled" Value="false">
        <Setter Property="Foreground" Value="{DynamicResource LinkButtonTextDisabled}" />
      </Trigger>
    </Style.Triggers>
  </Style>

  <Style TargetType="controls:ModernDialog">
    <Setter Property="BackgroundContent" Value="{DynamicResource WindowBackgroundContent}" />
    <Setter Property="FontFamily" Value="{DynamicResource DefaultFontFamily}" />
    <Setter Property="FontSize" Value="{DynamicResource DefaultFontSize}" />
    <Setter Property="Foreground" Value="{DynamicResource WindowText}" />
    <!-- Setter Property="MaxWidth" Value="640" />
    <Setter Property="MaxHeight" Value="640" / -->
    <Setter Property="MinWidth" Value="128" />
    <Setter Property="MinHeight" Value="42" />
    <Setter Property="ShowInTaskbar" Value="False" />
    <Setter Property="ResizeMode" Value="CanResizeWithGrip" />
    <Setter Property="SizeToContent" Value="WidthAndHeight" />
    <Setter Property="ShowInTaskbar" Value="False" />
    <Setter Property="UseLayoutRounding" Value="True" />
    <Setter Property="TextOptions.TextFormattingMode" Value="Display" />
    <Setter Property="xc:ModernDialogCloser.DialogCloser" Value="{Binding DialogCloseResult}" />
    <Setter Property="Focusable" Value="True" />
    <Setter Property="KeyboardNavigation.IsTabStop" Value="True" />

    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="controls:ModernDialog">
          <Border Background="{DynamicResource WindowBackground}" Margin="{Binding Source={x:Static shell:SystemParameters2.Current}, Path=WindowNonClientFrameThickness}">
            <AdornerDecorator>
              <Grid>
                <Border BorderBrush="{DynamicResource WindowBorder}" BorderThickness="1">
                  <Grid>
                    <!-- window background content -->
                    <ContentControl Content="{TemplateBinding BackgroundContent}" />

                    <!-- top blob -->
                    <Grid VerticalAlignment="Top" >
                      <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                      </Grid.ColumnDefinitions>

                      <Canvas Grid.Column="0" Width="{Binding ElementName=WindowBlob, Path=Width}" Margin="0,0,3,0">
                        <Rectangle x:Name="WindowBlob"
                                 Fill="{DynamicResource Accent}"
                                 Canvas.Top="0" Canvas.Left="0" Width="18" Margin="0,0,3,0" Height="33" />
                      </Canvas>

                      <!-- title -->
                      <Label Grid.Column="1"
                           ToolTip="{Binding Title}"
                           ToolTipService.IsEnabled="True"
                           HorizontalAlignment="Left"
                           HorizontalContentAlignment="Left"
                           VerticalAlignment="Center"
                           VerticalContentAlignment="Center"
                           >
                        <TextBlock DataContext="{Binding Title}"
                                 Text="{Binding Converter={StaticResource ToUpperConverter}}"
                                 FontFamily="Segoe UI"
                                 FontSize="18"
                                 TextOptions.TextFormattingMode="Display"
                                 TextTrimming="CharacterEllipsis"
                                 TextWrapping="NoWrap"
                                 HorizontalAlignment="Left" VerticalAlignment="Center" />
                      </Label >

                      <StackPanel Grid.Column="2" Orientation="Horizontal" HorizontalAlignment="Right"
                                syscmd:WindowChrome.IsHitTestVisibleInChrome="True">
                        <Grid>
                          <Button Command="{Binding CloseCommand}"
                                CommandParameter="{Binding DefaultCloseResult, Mode=OneWay}"
                                ToolTip="Close"
                                HorizontalAlignment="Right" VerticalAlignment="Top"
                                Style="{StaticResource MsgSystemButton}">
                            <Button.Content>
                              <Grid Width="32" Height="30"
                                  HorizontalAlignment="Center" VerticalAlignment="Center"
                                  RenderTransform="1,0,0,1,0,1">

                                <Path Data="M0,0 L8,7 M8,0 L0,7 Z" Width="8" Height="7"
                                    VerticalAlignment="Center" HorizontalAlignment="Center"
                                    Stroke="{Binding Foreground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Button}}"
                                    StrokeThickness="2"  />
                              </Grid>
                            </Button.Content>
                          </Button>
                        </Grid>
                      </StackPanel>
                    </Grid>

                    <Grid Margin="9,32, 0,0">
                      <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <!-- RowDefinition Height="Auto" / -->
                      </Grid.RowDefinitions>

                      <!-- content -->
                      <ContentControl Grid.Row="0" Margin="3" Content="{TemplateBinding Content}" x:Name="MessageContent"
                                      FocusVisualStyle="{x:Null}"
                                      Focusable="False"
                                      SnapsToDevicePixels="True" />

                      <!-- buttons
                    <ItemsControl Grid.Row="1" ItemsSource="{TemplateBinding Buttons}" HorizontalAlignment="Right">
                      <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                          <StackPanel Orientation="Horizontal" />
                        </ItemsPanelTemplate>
                      </ItemsControl.ItemsPanel>
                    </ItemsControl>
                     -->
                    </Grid>
                  </Grid>
                </Border>
                <Border BorderBrush="{DynamicResource WindowBorderActive}"
                        BorderThickness="1"
                        Visibility="{Binding IsActive, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Converter={StaticResource BooleanToVisibilityConverter}}" />
              </Grid>
            </AdornerDecorator>
          </Border>
        </ControlTemplate>
      </Setter.Value>
    </Setter>

    <!-- Defines outer window border frame and shadow ??? -->
    <Setter Property="shell:WindowChrome.WindowChrome">
      <Setter.Value>
        <shell:WindowChrome CornerRadius="0" GlassFrameThickness="1" UseAeroCaptionButtons="False" />
      </Setter.Value>
    </Setter>
  </Style>

</ResourceDictionary>